package main.com.hushengjin.demo;

import main.com.hushengjin.factory.AbstractFactory;
import main.com.hushengjin.model.Color;
import main.com.hushengjin.model.Shape;
import main.com.hushengjin.producer.FactoryProducer;

public class AbstractFactoryPatternDemo {
    public static void main(String[] args) {
        //获取形状工厂
        AbstractFactory shapeFactory = FactoryProducer.getFactory("Shape");

        //获取形状了circle的对象
        Shape circle = shapeFactory.getShape("circle");
        circle.draw();

        //获取形状为rectangle的对象
        Shape rectangle = shapeFactory.getShape("rectangle");
        rectangle.draw();

        //获取形状为square的对象
        Shape square = shapeFactory.getShape("square");
        square.draw();

        //获取颜色工厂
        AbstractFactory colorFactory = FactoryProducer.getFactory("color");

        //获取颜色为Red的对象
        Color red = colorFactory.getColor("red");
        red.fill();

        //获取颜色为green的对象
        Color green = colorFactory.getColor("green");
        green.fill();

        //获取颜色为blue的对象
        Color blue = colorFactory.getColor("blue");
        blue.fill();
    }
}
